﻿using System;
using CardLogistics.Web.Components;
using System.Data;
using System.Text;

namespace CardLogistics.Web.MainPage.SelectPage
{
    public partial class SelContract : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDLL(ddlsupName, "basic_suppliers", "suppliersname", "suppliersid", " and STATUS=0 and ISDELETE=0");  //供应商
                BindRpt(1);
            }
        }
        /// <summary>
        /// 绑定Rpt数据
        /// </summary>
        private void BindRpt(int pageIndex)
        {
            int recordCount = 0;
            int pageCount = 0;
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append(" IsSubmit=5 ");
            if (txt_NOName.Text.Trim().Length > 0)
                sbStr.Append(" and (CONNAME like '%" + txt_NOName.Text.Trim() + "%' or CONNO like '%" + txt_NOName.Text.Trim().ToUpper() + "%') ");
            if (ddlsupName.SelectedIndex != 0)
                sbStr.Append(" and SuppId='" + ddlsupName.Value + "'");//供应商
            if (txt_StartData.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(SIGNDATE,'yyyy-MM-dd')>='" + txt_StartData.Text.Trim() + "'");
            if (txt_EndData.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(SIGNDATE,'yyyy-MM-dd')<='" + txt_EndData.Text.Trim() + "'");
            if (Request.QueryString["type"] != null)
            {
                if (Request.QueryString["type"] == "order")
                    sbStr.Append(" and allTotal>dTotal ");
                else if (Request.QueryString["type"] == "cardret")//卡片退货
                    sbStr.Append(" and ID NOT IN (select conid from cardrecovery_returncard  where issubmit!=4 )");//每个合同批次只能退货一次
            }

            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_purchase_contract_detail", "ID", "  ConNO,BatchNO desc ", WebPageSize, pageIndex, sbStr.ToString(), "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt(WebPageIndex);
        }

        protected void btn_Search_Click(object sender, EventArgs e)
        {
            BindRpt(1);
        }
    }
}